package com.ws.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ws.entity.Team;
import com.ws.entity.User;
import com.ws.mapper.TeamMapper;
import com.ws.service.TeamService;
import com.ws.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeamServiceImpl implements TeamService {

    @Autowired
    private TeamMapper teamMapper;

    @Override
    public Result getTeamListForPage(Integer type, Integer isOnSale, int pno, int psize) {
        Page<Team> p = new Page<>(pno,psize);
        Page<Team> pageResult = teamMapper.getTeamListForPage(type, isOnSale, p);
        //提取分页中的数据
        List<Team> teamList = pageResult.getRecords();

        JSONObject data = new JSONObject();
        data.put("list",teamList);

        //传入分页相关参数
        JSONObject page = new JSONObject();
        page.put("pno",pno);
        page.put("psize",psize);
        page.put("pCount",pageResult.getPages());
        page.put("totalElements",pageResult.getTotal());
        data.put("page",page);
        return Result.end(200,data,"获取成功");
    }
}
